package name.pilgr.soaboard.controller;

import name.pilgr.soaboard.model.DataServiceJDBC;
import name.pilgr.soaboard.view.Body;
import name.pilgr.soaboard.view.Header;
import name.pilgr.soaboard.view.ObservantPanel;
import name.pilgr.soaboard.view.ObservantPanelTable;

import com.vaadin.ui.ProgressIndicator;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

@SuppressWarnings("serial")
public class UiController extends VerticalLayout{
	
	Header header;
	Body body;
	ProgressIndicator progress;
	Window mainWindow;
	
	DataServiceJDBC jdbcService1;
	ObservantPanelTable dashPanel1;
		
	public UiController(Window window) {
		this.mainWindow = window;
		// For refresh visual component after modify it in async mode :)
		progress = new ProgressIndicator();
		progress.setWidth("0px");
		progress.setHeight("0px");
		progress.setPollingInterval(500);
		
		header = new Header();
		body = new Body();
		
		setMargin(true);	
		setSpacing(true);	
		
		// Add the main components for the UI.
		this.addComponent(progress);
		this.addComponent(header);
		this.addComponent(body);
		
		addPanel1();
		
		window.setContent(this);
			
	}

	public void refreshAll() {
		jdbcService1.forcedRequestData();
	}
	
	public void addPanel1(){
		jdbcService1 = new DataServiceJDBC(5000);
		dashPanel1 = new ObservantPanelTable(jdbcService1);
		body.addComponent(dashPanel1);
	}
	
}
